package com.goktech.project.hmw.dao.impl;

import com.goktech.project.hmw.dao.IFwlsjDao;
import com.goktech.project.hmw.mapper.Fwlsj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class FwlsjDaoImpl implements IFwlsjDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	/**
	 * 通过area_id获取访问两数据
	 *
	 * @param area_id
	 * @return
	 */
	@Override
	public List<Fwlsj> listFwlsjByArea_id(String area_id) {
		String sqlStr="select * from fwlsj where area_id = ?";
		List<Fwlsj> list=jdbcTemplate.query(sqlStr,new Object[]{area_id},new BeanPropertyRowMapper<>(Fwlsj.class));
		if(list!=null&&list.size()>0){
			return list;
		}else{
			return null;
		}
	}

	/**
	 * 通过访问方式返回访问量集合
	 *
	 * @param visit_type
	 * @return
	 */
	@Override
	public List<Fwlsj> listFwlsjByVisit_type(String visit_type) {
		String sqlStr="select * from fwlsj where visit_type = ?";
		List<Fwlsj> list=jdbcTemplate.query(sqlStr,new Object[]{visit_type},new BeanPropertyRowMapper<>(Fwlsj.class));
		if(list!=null&&list.size()>0){
			return list;
		}else{
			return null;
		}
	}

	/**
	 * 通过开始时间结束时间返回访问量数据集合
	 *
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@Override
	public List<Fwlsj> listFwlsjByTime(String startTime, String endTime) {
		String sqlStr="select * from fwlsj where visit_date >=? and visit_date<= ?";
		List<Fwlsj> list=jdbcTemplate.query(sqlStr,new Object[]{startTime,endTime},new BeanPropertyRowMapper<>(Fwlsj.class));
		if(list!=null&&list.size()>0){
			return list;
		}else{
			return null;
		}
	}
}
